import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/10 20:26
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.countSegments("Hello, my name is John");
    }
    public int countSegments(String s) {
        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == ' ') {
                continue;
            }
            int left = i;
            while (left < s.length() && s.charAt(left) != ' ') {
                left++;
            }
            ans++;
            i = left;
        }
        return ans;
    }
}
